package com.stars.home.utils.glide

import android.content.Context
import android.widget.ImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.Priority
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.stars.home.R

/**
 *on 2022/7/28
 */
object GlideUtils {


    fun getOne(context: Context,radius:Int): RequestOptions {

        return RequestOptions.bitmapTransform(GlideCircleTransform(context))
                .transform(GlideRoundTransform(context, radius))
                .placeholder(R.drawable.bg_need_error)
                .error(R.drawable.bg_need_error)
    }


    fun getTwo(): RequestOptions {

        return RequestOptions()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(R.drawable.bg_need_error)
                .error(R.drawable.bg_need_error)
                .skipMemoryCache(true)
    }
    fun getThree(): RequestOptions{

        return RequestOptions()
                .centerCrop()
                .skipMemoryCache(true)
                .priority(Priority.HIGH)
                .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
                .error(R.drawable.bg_need_error)


    }

    fun getFour(context: Context?): RequestOptions{

        return RequestOptions()
                .placeholder(R.drawable.ic_default_avatar)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .skipMemoryCache(true)
                .transform(GlideCircleTransform(context))
                .error(R.drawable.ic_default_avatar)
    }

    fun getFive(context: Context?,radius:Int,with:Int,high:Int): RequestOptions {

        return RequestOptions()
                .override(with, high)
                .transform(GlideRoundTransform(context, radius))
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(R.drawable.bg_need_error)
                .error(R.drawable.bg_need_error)
                .skipMemoryCache(true)
    }
    fun getSix(with:Int,high:Int): RequestOptions {

        return RequestOptions()
                .override(with, high)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .placeholder(R.drawable.bg_need_error)
                .error(R.drawable.bg_need_error)
                .skipMemoryCache(true)
    }



    //可设置圆角
    fun lImg(context: Context?, url: String, radius:Int,imageView: ImageView?) {
        if (context != null) {
            Glide.with(context)
                    .load(url)
                    .apply(getOne(context,radius))
                    .into(imageView!!)
        }
    }

    //没有限制图片的大小
    fun lImg(context: Context?, url: String?, imageVie: ImageView?) {
        Glide.with(context!!)
                .load(url)
                .apply(getTwo())
                .into(imageVie!!)
    }


    fun lImg(context: Context?, url: String?, with:Int,high:Int,imageVie: ImageView?) {
        Glide.with(context!!)
                .load(url)
                .apply(getSix(with,high))
                .into(imageVie!!)
    }

    fun lImg(context: Context?, url: String?, radius:Int,with:Int,high:Int,imageVie: ImageView?) {
        Glide.with(context!!)
                .load(url)
                .apply(getFive(context,radius,with,high))
                .into(imageVie!!)
    }

    fun lGif(context: Context?, url: String?, imageVie: ImageView?) {
        Glide.with(context!!)
                .load(url)
                .apply(getThree())
                .into(imageVie!!)
    }

    fun lAvator(context: Context?, url: String?, imageVie: ImageView?){
        Glide.with(context!!)
                .load(url)
                .apply(getFour(context))
                .into(imageVie!!)
    }


}
